package com.example.conversorcplp;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Conversao extends Activity {
	
	Double tax;
	Double tax2;
	Double v1, v2;
	Double dollar;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.conversao);
		String po = Paises.paisorigem;
    	String pd = Paises.paisdestino;
    	
    	if(po == null || pd == null )
    	{
    		Toast.makeText(getApplicationContext(), "Nao introduziu paises !", Toast.LENGTH_SHORT).show();
    		finish();
    	}
    	
    	TextView textView = (TextView) findViewById(R.id.textView1);
    	textView.setText(po);

    	TextView textView2 = (TextView) findViewById(R.id.textView2);
    	textView2.setText(pd);
		Button btn = (Button) findViewById(R.id.button1);
		
		btn.setOnClickListener(new OnClickListener(){
			
		    public void onClick(View v){ 
		    	
		    	String po = Paises.paisorigem;
		    	String pd = Paises.paisdestino;

		    	TextView textView = (TextView) findViewById(R.id.textView1);
		    	textView.setText(po);
		
		    	TextView textView2 = (TextView) findViewById(R.id.textView2);
		    	textView2.setText(pd);
		
		    	EditText value1 = (EditText) findViewById(R.id.numeroo);
		
		    	TextView value2 = (TextView) findViewById(R.id.numerod);
		    	
		    	TextView value3 = (TextView) findViewById(R.id.dollar);
		
		    	//TextView first = (TextView) findViewById(R.id.textView1);
		
		    	//TextView second = (TextView) findViewById(R.id.textView2);
		
		    	tax = 0.0;
		    	tax2 = 0.0;
		
		    	if(textView.getText() == "Kwanza") {
		    		tax = Rates.kwanzaRate;
		    	}
		    	if(textView.getText() == "Real") {
		    		tax = Rates.brazilRate;
		    	}
		    	if(textView.getText() == "Escudo CV") {
		    		tax = Rates.cverdeRate;
		    	}
		    	if(textView.getText() == "Franco CFA") {
		    		tax = Rates.equaRate;
		    	}
		    	if(textView.getText() == "Franco Guineense") {
		    		tax = Rates.guineRate;
		    	}
		    	if(textView.getText() == "Metical") {
		    		tax = Rates.mocambiRate;
		    	}
		    	if(textView.getText() == "Euro") {
		    		tax = Rates.eurRate;
		    	}
		    	if(textView.getText() == "Dobra") {
		    		tax = Rates.stpRate;
		    	}
		
		    	if(textView.getText() == "Dollar USD") {
		    		tax = Rates.timorRate;
		    	}
		
		    	if(textView2.getText() == "Kwanza") {
		    		tax2 = Rates.kwanzaRate;
		    	}
		    	if(textView2.getText() == "Real") {
		    		tax2 = Rates.brazilRate;
		    	}
		    	if(textView2.getText() == "Escudo CV") {
		    		tax2 = Rates.cverdeRate;
		    	}
		    	if(textView2.getText() == "Franco CFA") {
		    		tax2 = Rates.equaRate;
		    	}
		    	if(textView2.getText() == "Franco Guineense") {
		    		tax2 = Rates.guineRate;
		    	}
		    	if(textView2.getText() == "Metical") {
		    		tax2 = Rates.mocambiRate;
		    	}
		    	if(textView2.getText() == "Euro") {
		    		tax2 = Rates.eurRate;
		    	}
		    	if(textView2.getText() == "Dobra") {
		    		tax2 = Rates.stpRate;
		    	}
		    	if(textView2.getText() == "Dollar USD") {
		    		tax2 = Rates.timorRate;
		    	}
		
		    	if(! value1.getText().toString().equals("")) {
			
		    		v1 = Double.valueOf(value1.getText().toString());
			
		    		dollar = v1 / tax;
			
		    		v2 = dollar * tax2;
			
		    		value2.setText(String.valueOf(v2));
		    		
		    		value3.setText(String.valueOf(dollar));
		    	}
		    }
		});
		
	}
	protected void onResume(){
		super.onResume();
		EditText value1 = (EditText) findViewById(R.id.numeroo);
		TextView value2 = (TextView) findViewById(R.id.numerod);
		if(! value1.getText().toString().equals("")) {
			value2.setText(String.valueOf(v2));
		}
	}
}
